<template>
    <h2>房型信息列表展示</h2>
    <input type="button" value="导出" @click="ImportFiles"/>
    <table border="1">
       <thead>
        <tr style="background-color: rgba(43, 0, 255, 0.685);">
            <td>房型编号</td>
            <td>房型名称</td>
            <td>门市价</td>
            <td>押金</td>
            <td>面积</td>
            <td>可住人数</td>
            <td>房型图片</td>
            <td>是否加床</td>
            <td>是否投放</td>
            <td>操作</td>
        </tr>
       </thead>
       <tbody>
        <tr v-for="item in rtype">
            <td>{{item.RT_Id}}</td>
            <td>{{item.RT_Name}}</td>
            <td>{{item.RT_Price}}</td>
            <td>{{item.RT_Deposit}}</td>
            <td>{{ item.RT_Size }}</td>
            <td>{{item.RT_Num}}</td>          
            <td>
                <img style="width:50px;height:50px;" :src="item.RT_Img"/>
            </td>
            <td>{{item.RT_AddBed==true?"加床":"不加床"}}</td>
            <td>{{ item.RT_State==true?"投放":"不投放" }}</td>
            <td>
                <a href="#" v-if="item.RT_State==false" @click="ChangeState(item.RT_Id,0)">投放</a>
                <a href="#" v-else="item.RT_State==true" @click="ChangeState(item.RT_Id,1)">不投放</a>
            </td>
        </tr>
       </tbody>
    </table>
</template>

<script setup lang="ts">
 import {ref,onMounted} from 'vue'
 import axios from 'axios'
 const ChangeState=(RT_Id:number,StateId:number)=>{
    axios.get('https://localhost:44320/api/Room/ChangeRoomType',{
        params:{
            RT_Id:RT_Id,
        StateId:StateId
        }
    })
    .then(res=>{
        if(res.data>0)
        {
            alert('修改成功');
            loadData();
        }
        else
        {
            alert('修改失败');
        }
    })
 }
//导出数据
const ImportFiles=()=>{
    axios.get('https://localhost:44320/api/Room/ExportFile',{
        params:{
            PathName:"C:\\Users\\23285\\Desktop\\ExportFile\\Test.xlsx"//转义
        }
    })
    .then(res=>{
        console.log(res.data);
        if(res.data>0)
        {
            alert('导出成功');
        }
        else
        {
            alert('导出失败');
        }
    })
}


 const rtype=ref([{
    "RT_Id": 1,
    "RT_Name": "普通标间",
    "RT_Price": 100,
    "RT_Deposit": 100,
    "RT_Size": 50,
    "RT_Num": 1,
    "RT_AddBed": false,
    "RT_Img": "https://localhost:44320/Images/1.png",
    "RT_Info": "满足基本出差需要",
    "RT_State": true
  }])
  onMounted(()=>{
    loadData();
  })
  const loadData=()=>{
    axios.get('https://localhost:44320/api/Room/TypeShow')
    .then(res=>{
        rtype.value=res.data;
    })
  }

</script>